<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <title>个性化开关编辑</title>
        <script type="text/javascript" src="/static/xadmin/js/jquery.min.js"></script>
        <#include "/common/common.ftl">
    </head>
    <body style="background-color:#fff">
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" lay-filter="example">
                    <input type="hidden" name="tokens" value="${tokens!}">
                    <input type="hidden" name="id" value="${(info.id)!}">
                        
                    <div class="layui-form-item" >
                          <label class="layui-form-label">
                              <span class="x-red">*</span>自动功能类型：
                         </label>
                        <div class="layui-input-inline">
                              <select title="自动功能类型" class="ui selection search dropdown" required="" lay-verify="required" lay-search    class="select" lay-filter="ctype" name="type" id="ctype" <#if info?? && info.type??> disabled="disabled"  </#if>  >
		                                    <option value="">请选择</option>
		                                    <option value="1000" <#if info?? && info.type?? && info.type==1000> selected</#if> >通过好友请求自动回复</option>
											<option value="1001" <#if info?? && info.type?? && info.type==1001> selected</#if> >自动抢红包</option>
											<option value="1002" <#if info?? && info.type?? && info.type==1002> selected</#if> >自动通过好友请求</option>
											<option value="1003" <#if info?? && info.type?? && info.type==1003> selected</#if> >自动通过群邀请链接请求</option>
											<option value="1004" <#if info?? && info.type?? && info.type==1004> selected</#if> >自动收账</option>
		                      </select>
                        </div>
                    </div>
                    
                    
                    <div class="layui-form-item">
                          <label class="layui-form-label">
                              <span class="x-red">*</span>自动功能状态：
                         </label>
                        <div class="layui-input-inline">
                              <select title="开关状态" class="ui selection search dropdown" required="" lay-verify="required" lay-search    class="select" name="state" >
		                                    <option value="">请选择</option>
											<option value="0" <#if info?? && info.state?? && info.state==0> selected</#if> >开启</option>
		                                    <option value="1" <#if info?? && info.state?? && info.state==1> selected</#if> >关闭</option>
		                      </select>
                          </div>
                    </div>
                    
                    <div class="layui-form-item" id="returnDiv" >
                        <label class="layui-form-label">
                            <span class="x-red">*</span>回复语：
                        </label>
                        <div class="layui-input-inline">
                             <textarea  name="returnString"  class="layui-textarea" maxlength="500">${(info.returnString)!}</textarea> 
                        </div>
                    </div>
                    
                    
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                    </div>
              </form>
            </div>
        </div>
        
        
        <script type="text/javascript">
		  $(function() {
			if($("#ctype").val()  &&  $("#ctype").val()!='1000'){
			     alert($("#ctype").val())
			     $("#returnDiv").remove();
			}
		  }) 
        </script>
        
        <script type="text/javascript">
            layui.use(['form', 'layer'], function () {
                var form = layui.form;
                var layer = layui.layer;
                var $ = layui.$;

                
                form.on('submit(add)', function (data) {
                    $('.layui-form-item .layui-btn').prop('disabled', true);
                    $('.layui-form-item .layui-btn').text('提交中...');
                    var id = $("input[name='id']").val();
                    var url = (id == null || id === '') ? '/user/commonState/add' : '/user/commonState/update';
                    $.ajax({
                        type: 'post',
                        url: url,
                        data: data.field,
                        dataType: 'json',
                        success: function (data) {
                            if (data.code !== 0) {
                                $('.layui-form-item .layui-btn').prop('disabled', false);
                                $('.layui-form-item .layui-btn').text('提交');
                                layer.msg(data.msg);
                                return false;
                            }
                            xadmin.close();
                            layer.closeAll();
                            parent.reload();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $('.layui-form-item .layui-btn').prop('disabled', false);
                            $('.layui-form-item .layui-btn').text('提交');
                            layer.msg('系统异常');
                        }
                    });
                    return false;
                });
                
                
                form.on('select(ctype)', function(data){
					  var value = data.value;
					  if(value !='' && value !='1000'){
					    $("#returnDiv").addClass("returnDivStyle");
					  }else{
					    $("#returnDiv").removeClass("returnDivStyle");
					  } 
				});
                
            });
            
        </script>
        <style type="text/css">
            .layui-form-label {
                width: 200px;
            }
            
            .returnDivStyle {
			  display:none;
			}
        </style>
    </body>
</html>
